package model;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import model.base.BaseDaliyItems;

@SuppressWarnings("serial")
public class DaliyItems extends BaseDaliyItems<DaliyItems> {
    public static final DaliyItems dao = new DaliyItems().dao();
    

	public DaliyItems findFirstByContentAndType(String content , Integer type){
        return this.findFirst(" SELECT tdi.* FROM t_daliy_items tdi WHERE tdi.content = ? AND tdi.type = ?  LIMIT 1 " , content , type);
    }

	public List<Record> getOptionsList(){
        return Db.find(" SELECT tdi.id AS value , tdi.content AS title FROM t_daliy_items tdi  "  );
    }

	public int getMaxOrderNum(){
    	return Db.queryLong(" SELECT IFNULL(MAX(tdi.orderNum),0) FROM t_daliy_items tdi WHERE tdi.type = ? " , getType() ).intValue() + 1 ;
    }
	
	public List<Record> findTitleByType(Integer type){
        return Db.find(" SELECT DISTINCT(tdi.title)  FROM t_daliy_items tdi WHERE tdi.type = ? "  , type);
    }

	public List<Record> findByTitleAndType(Integer type , String title){
        return Db.find(" SELECT tdi.content , tdi.id , tdi.duration FROM t_daliy_items tdi WHERE tdi.type = ? AND tdi.title = ? ORDER BY tdi.orderNum "  , type , title);
    }

	public void setMaxOrderNum(){
    	if (null == getOrderNum()) {
			setOrderNum(getMaxOrderNum());
		}
    }


	public List<DaliyItems> findByContentAndType(String content , Integer type){
        return this.find(" SELECT tdi.* FROM t_daliy_items tdi WHERE tdi.content = ? AND tdi.type = ?  ORDER BY tdi.orderNum " , content , type);
    }

	public List<Record> getOptionsList(Integer type){
        return Db.find(" SELECT tdi.id AS value , tdi.content AS title FROM t_daliy_items tdi WHERE tdi.type = ?  ORDER BY tdi.orderNum "  , type );
    }
}
